import TestView from "./views/TestView";
import BaseApp, { ViewZOrder } from "./base/BaseApp";
import ComfrimView from "./views/common/ComfrimView";
import { Button, Component, Label, _decorator } from "cc";

const { ccclass, property } = _decorator;

@ccclass
export default class App extends Component {
	@property(Label)
		label: Label = null;

	// use this for initialization
	onLoad() {
		BaseApp.instance().appComponent = this;
		this.label.string = "这是测试场景了";

		this.node.getChildByName("button").on("click", this.onBtnClickEvent, this);
		this.node.getChildByName("button3").on("click", this.onBtnClickEvent, this);
		this.node.getChildByName("button2").on("click", this.onBtnClickClose, this);
	}

	onBtnClickEvent(btn: Button) {
		if (btn.node.name == "button3") {
			const data = {
				"string": "这是内容", "title": "标题x", "comfirmCall": () => {
					console.log("您按了确认");
				}, "frameType": 1
			};

			BaseApp.instance().openView(ComfrimView, data);
		} else {
			BaseApp.instance().openView(TestView, null, ViewZOrder.TopLayer, false, 2);
		}
	}

	onBtnClickClose(event) {
		BaseApp.instance().runScene("scene");
	}

	// called every frame
	update(dt) {

	}
}
